< previous page page_247 next page >

Page 247
Visual Basic does have features for rubber-stamping common code. Instead, it is better to delegate common behavior in form objects to classes. Therefore, IInfoMaintenance becomes InfoMaintenance. Its methods might look like Listing 11.3.
LISTING 11.3. SOME METHODS FORInfoMaintenance.

9f8044bafea36a1f728739c0bb58ef4c.gif
 1: Public Sub clickedAddBtn(ByRef argObject, argString As String)
 2:    If TypeOf argObject Is TextBox Then
 3:      argObject.Text = argObject.Text & argString
 4:    End If
 5:    If TypeOf argObject Is Label Then
 6:      argObject.Caption = argObject.Caption & argString
 7:    End If
 8:    If TypeOf argObject Is ListBox Then
 9:       argObject.AddItem argObject.List(argObject.ListIndex)_ argString
10:    End If
11:    If TypeOf argObject Is ComboBox Then
12:       argObject.AddItem argObject.List(argObject.ListIndex)_ argString
13:    End If
14: End Sub
15:
16: Public Sub clickedModifyBtn(argObject As Object, argString As String)
17:    If TypeOf argObject Is TextBox Then
18:       argObject.Text = argString
19:    End If
20:    If TypeOf argObject Is Label Then
21:       argObject.Caption = argString
22:    End If
23: End Sub
24:
25: Public Sub clickedDeleteBtn(argObject As Object)
26: If TypeOf argObject Is TextBox Then
27:      argObject.Text = &rdqup;
28:    End If
29:    If TypeOf argObject Is Label Then
30:      argObject.Caption = 
31:    End If
32:    If TypeOf argObject Is ListBox Then
33:      argObject.RemoveItem argObject.ListIndex
34:    End If
35:    If TypeOf argObject Is ComboBox Then
36:      argObject.RemoveItem argObject.ListIndex
37:    End If
38: End Sub

 
< previous page page_247 next page >

If you like this book, buy it!